/* 
 *  Incub - incubate your baby robot
 *  Copyright (C) 2008 Stanislaw Szymczyk
 *  e-mail: sszymczy@gmail.com   www: http://cogville.cog-lab.com
 *
 *  This file is part of Incub.
 *
 *  Incub is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Incub is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Incub.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
 
#include "Camera.h"

using std::string;

Camera::Camera() {
	display = true;
	type = Camera::COLOR;
	horiz_res = 640;
	vert_res = 480;
	buffer = NULL;
	reallocateBuffer();
	zNear = 0.01;
	zFar = 100;
}

Camera::~Camera() {
	if(buffer != NULL) free(buffer);
}

void Camera::setDisplay(string dis) {
	if(dis=="true")	display = true;
	else display = false;
}

bool Camera::getDisplay() {
	return display;
}

void Camera::setType(string t) {
	if(t=="mono") type = Camera::MONO;
	else if(t=="color") type = Camera::COLOR;
	else if(t=="depth") type = Camera::DEPTH;
	reallocateBuffer();
}

Camera::camera_t Camera::getType() {
	return type;
}

void Camera::setResolution(string res) {
	sscanf(res.c_str(), "%d %d", &horiz_res, &vert_res);
	reallocateBuffer();
}

int Camera::getHorizontalResolution() {
	return horiz_res;
}

int Camera::getVerticalResolution() {
	return vert_res;
}

void Camera::reallocateBuffer() {
	buffer = (unsigned char*) realloc(buffer, horiz_res * vert_res * getDepth());
}

int Camera::getDepth() {
	switch(type) {
		case MONO:
			return 1;
		case COLOR:
			return 3;
		case DEPTH:
			return 4;
		default:
			return 3;
	}
}

void* Camera::getBuffer() {
	return (void*) buffer;
}

void Camera::setZNear(string zNear) {
	this->zNear = atof(zNear.c_str());
}

float Camera::getZNear() {
	return zNear;
}

void Camera::setZFar(string zFar) {
	this->zFar = atof(zFar.c_str());
}

float Camera::getZFar() {
	return zFar;
}
